package com.journaldev.threadpool.executor;

import java.util.concurrent.*;

import com.journaldev.threadpool.WorkerThread;

/**
 * 使用 Executors 框架创建了一个固定的线程池的测试程序
 * @author:chenhs E-mail:hson08_chen@163.com
 * Created on 2017年9月8日 上午11:30:58
 */
public class SimpleThreadPool {

	public static void main(String[] args) {
		ExecutorService executor = Executors.newFixedThreadPool(5);

		for(int i = 0; i < 10; i++){
			Runnable worker = new WorkerThread(" "+ i);
			executor.execute(worker);
		}
		// This will make the executor accept no new threads and finish all existing threads in the queue  
		executor.shutdown();
		while(!executor.isTerminated()){
		// Wait until all threads are finish,and also you can use "executor.awaitTermination();" to wait  
		}
		System.out.println("Finished all threads");
	}

}
